package com.eigaland.change_machine.business.movelistfullscreen

import com.eigaland.change_machine.BuildConfig
import com.eigaland.change_machine.business.movielist.MovieListItemVM
import com.eigaland.change_machine.business.network.RetrofitClient
import com.eigaland.change_machine.displaymodel.MovieListFullScreenDisplayModel
import com.eigaland.change_machine.util.UserManager
import com.eigland.eigaland_lib.base.BaseRepository
import com.eigland.eigaland_lib.network.MovieService
import movie6.posprintercept2.extensions.splitList

public class MovieFullScreenFragmentRepository :BaseRepository(){

   suspend fun getMovieList():MovieListFullScreenDisplayModel{
        var displayModel = MovieListFullScreenDisplayModel()

        var resultList = ArrayList<List<MovieListItemVM>>()
        var result =
            UserManager.cinemaId?.let {
                RetrofitClient.getService(MovieService::class.java, BuildConfig.domain).movieShowingList(
                    it
                ).await()
            }
        result?.success.let {
            var list = ArrayList<MovieListItemVM>()
            it?.content?.forEach {it ->
                var item = MovieListItemVM()
                item.movieId = it.movie.uuid
                item.movieName = it.movie.name
                item.imageUrl = it.movie.posterUrl
                list.add(item)

            }
            resultList.addAll(list.splitList(12))

        }
        displayModel.movieList = resultList
       return displayModel

    }
}